ArtTreeView = function () {
    //  CMap.ClassCopy(this, new UIBase());
}
ArtTreeView.prototype = {
    m_parentDiv: null,
    m_rootDiv: null,
    m_clearBtn: null,
    o_isOpen: true,
    prjDir: "",
    Init: function (m_parentDiv, prjDir) {
        uiRoot.o_ArtTreeView = this;
        m_parentDiv.o_ArtTreeView = this;
        this.m_parentDiv = m_parentDiv;
        this.prjDir = prjDir;
        this.m_rootDiv = CreateCard.CreateView(m_parentDiv, "ArtTreeView");
        this.m_rootDiv.style.width = "400px";
        this.m_rootDiv.style.height = "800px";
        this.m_rootDiv.style.backgroundColor = "#005588";
        this.m_rootDiv.o_thisObj = this;
        CardDrag_SetDrag(this.m_rootDiv)
        let thisObj = this;
        CreateCard.CreateBtn(this.m_rootDiv, "获取所有资源", function () {
            thisObj.loadAllArt();
        });
        this.m_clearBtn = CreateCard.CreateBtn(this.m_rootDiv, "关闭", function () {
            thisObj.m_rootDiv.style.display = "none";
        });
        this.m_clearBtn.style.left = "200px";
    },
    loadAllArt: function () {
        let midDir = "/ResourcesAB/txtData";
        let ignoreDir = "/.";
        let suffixArr = ".txt|.jpeg";
        let isTop = 0;
        let thisObj = this;
        WebPost_getDirFiles(this.prjDir, midDir, ignoreDir, suffixArr, isTop, function (dfStr) {
            let pathList = CFile_dfStrToFileList(dfStr, true);
            // for (let i = 0; i < pathList.length; i++) {
            //     let path = pathList[i];
            //     cc.log("...." + path.onlyPath)
            // }
            thisObj.CreateNodeTree(pathList)
            //log("获取所有资源...s__________" + dfStr);
        });
    },

    CreateNodeTree: function (pathList) {
        let nodeData = {}
        nodeData.isViewNode = true;
        nodeData.name = "root";
        nodeData.childDic = {}
        for (let i = 0; i < pathList.length; i++) {
            let pathObj = pathList[i];
            let onlyPath = pathObj.onlyPath;
            //cc.log("...." + onlyPath)
            if (onlyPath == null) {
                cc.error("...." + pathObj.path)
                continue
            }
            if (i > 100) {
                break;
            }
            if (nodeData.childDic[onlyPath.a] == null) {
                let data = {};
                data.isViewNode = true;
                data.name = "" + onlyPath.a;
                data.childDic = {}
                nodeData.childDic[onlyPath.a] = data;
            }
            if (nodeData.childDic[onlyPath.a].childDic[onlyPath.b] == null) {
                let data = {};
                data.isViewNode = true;
                data.name = "" + onlyPath.b;
                data.childDic = {}
                nodeData.childDic[onlyPath.a].childDic[onlyPath.b] = data;
            }
            if (nodeData.childDic[onlyPath.a].childDic[onlyPath.b].childDic[onlyPath.c] == null) {
                let data = {};
                data.isViewNode = true;
                data.name = "" + onlyPath.c;
                data.childDic = {}
                nodeData.childDic[onlyPath.a].childDic[onlyPath.b].childDic[onlyPath.c] = data;
            }

            let data = {};
            data.isViewNode = true;
            data.name = "" + onlyPath;
            data.data = pathObj;
            data.childDic = {}
            nodeData.childDic[onlyPath.a].childDic[onlyPath.b].childDic[onlyPath.c].childDic[onlyPath.d] = data;// pathObj.onlyPath.id;

        }

        this.tree_nodeRootObj = tree_genNode(nodeData, this.m_rootDiv, null, function (nodeData) {
            if (nodeData.data != null) {
                let thisObj = uiRoot.o_ArtTreeView
                let fullPath = thisObj.prjDir + "/" + nodeData.data.path
                cc.log("加载对象........" + fullPath)
                WebPost_FileRead(fullPath, "text", thisObj.S_OpenWeDataView)
            }
        });
        // this.tree_nodeRootObj.offsetLeft = this.offsetLeft;
        // this.tree_nodeRootObj.offsetTop = this.offsetTop;
        // this.tree_nodeRootObj.S_Refresh(null, this.offsetLeft, this.offsetTop);
        this.tree_nodeRootObj.initOffectX = 0;
        this.tree_nodeRootObj.initOffectY = 20;
        this.tree_nodeRootObj.S_Refresh(null, 0, 20);
    },

    S_OpenWeDataView: function (weDataStr) {
        cc.log("weDataStr........" + weDataStr)
        let weDataObj = CSUtils.WeData.S_DeSerializationString(weDataStr, false);

        WeDataNodeView.GetInstance().loadWeData(weDataObj);
    }
}


ArtTreeView.Open = function (m_parentDiv, prjDir) {
    if (uiRoot.o_ArtTreeView == null) {
        let o_ArtTreeView = new ArtTreeView();
        o_ArtTreeView.Init(m_parentDiv, prjDir);
    } else {
        uiRoot.o_ArtTreeView.o_isOpen = !m_parentDiv.o_ArtTreeView.o_isOpen;
        uiRoot.o_ArtTreeView.m_rootDiv.style.display = m_parentDiv.o_ArtTreeView.o_isOpen ? "none" : "block";
    }
}

